<template>

  <ContentWrapForm>
    <HeaderTitle title="人员伤亡模型管理" content="设置人员伤亡模型参数，定义报告使用模型。" :isdivider="false" />
  </ContentWrapForm>
  <el-form ref="formRef" class="-mb-15px" v-loading="formLoading" :inline="true" :model="formData" :rules="formRules"
    label-width="130px">
    <el-row>
      <el-col :span="24">
        <ContentWrapForm :title="'模型参数设置'">

          <div class="mdbj">
            <el-col :span="24">
              <ModelTitle :number="'一'" :content="'源于《GB/T 30352-2013 地震灾情应急评估》公式A.1、A.2'" />
            </el-col>
            <el-col :span="24" class="mdbj_content">
              <el-form :inline="true" class="demo-form-inline" :model="formData" :rules="formRules">
                <el-form-item label="死亡率公式" prop="model1.param1" :rules="[
                { required: true, message: '死亡率公式' },
              ]">
                  <div class="flex">
                    <el-select v-model="formData.model1.symbol" placeholder="请选择">
                      <el-option label="lg" value="lg" />
                      <el-option label="ln" value="ln" />
                    </el-select>
                    <div class="el-colC">
                      <span class="italic">R</span><sub>j</sub>
                    </div>
                    <div class="el-colC">
                      <span>=</span>
                    </div>
                    <div class="el-colC">
                      <span>—</span>
                    </div>
                    <el-input v-model="formData.model1.param1"
                      @input="(value) => (formData.model1.param1 = value.replace(/[^0-9.]/g, '').replace(/^(\d+\.\d{0,4}).*$/, '$1'))"
                      placeholder="保留四位小数" />
                    <el-icon>
                      <div class="el-colC">
                        <Plus />
                      </div>
                    </el-icon>
                    <el-input v-model="formData.model1.param2"
                      @input="(value) => (formData.model1.param2 = value.replace(/[^0-9.]/g, '').replace(/^(\d+\.\d{0,4}).*$/, '$1'))"
                      placeholder="保留四位小数" />
                    <div class="el-colC">
                      <span class="italic">I</span><sub>j</sub>
                    </div>
                    <el-icon>
                      <div class="el-colC">
                        <Minus />
                      </div>
                    </el-icon>
                    <el-input v-model="formData.model1.param3"
                      @input="(value) => (formData.model1.param3 = value.replace(/[^0-9.]/g, '').replace(/^(\d+\.\d{0,4}).*$/, '$1'))"
                      placeholder="保留四位小数" />
                    <div class="el-colC">
                      <span class="italic">I</span><sup>2</sup><sub>j</sub>
                    </div>
                  </div>
                </el-form-item>

                <el-form-item label="受伤与死亡比例" prop="model1.ratio" label-width="270px" :rules="[
                { required: true, message: '受伤与死亡比例必填' },
              ]">
                  <el-input maxlength="20" style="width: 220px;" :formatter="(value) => `${value}`.replace(/\D/g,'')"
                    :parser="(value) => value.replace(/\D/g,'')" v-model="formData.model1.ratio"
                    controls-position="right" />
                </el-form-item>
              </el-form>
            </el-col>
          </div>
          <div class="mdbj">
            <el-col>
              <ModelTitle :number="'二'" :content="'源于《GB/T 30352-2013 地震灾情应急评估》公式A.1、A.3'" />
            </el-col>
            <el-col :span="24" class="mdbj_content">
              <el-form :inline="true" class="demo-form-inline" :model="formData" :rules="formRules">
                <el-form-item label="死亡率公式" prop="model2.param1" :rules="[
                { required: true, message: '死亡率公式' },
              ]">
                  <el-col :span="24" class="flex">
                    <el-select v-model="formData.model2.symbol" placeholder="请选择">
                      <el-option label="lg" value="lg" />
                      <el-option label="ln" value="ln" />
                    </el-select>
                    <div class="el-colC">
                      <span class="italic">R</span><sub>j</sub>
                    </div>
                    <div class="el-colC">
                      <span>=</span>
                    </div>
                    <div class="el-colC">
                      <span>—</span>
                    </div>
                    <el-input v-model="formData.model2.param1"
                      @input="(value) => (formData.model2.param1 = value.replace(/[^0-9.]/g, '').replace(/^(\d+\.\d{0,4}).*$/, '$1'))"
                      placeholder="保留四位小数" />
                    <div class="el-colC">
                      <el-icon>
                        <Plus />
                      </el-icon>
                    </div>
                    <el-input v-model="formData.model2.param2"
                      @input="(value) => (formData.model2.param2 = value.replace(/[^0-9.]/g, '').replace(/^(\d+\.\d{0,4}).*$/, '$1'))"
                      placeholder="保留四位小数" />
                    <el-select v-model="formData.model2.symbol2" placeholder="请选择">
                      <el-option label="lg" value="lg" />
                      <el-option label="ln" value="ln" />
                    </el-select>
                    <div class="el-colC">
                      <span class="italic">I</span><sub>j</sub>
                    </div>
                    <div class="el-colC">
                      <el-icon>
                        <Plus />
                      </el-icon>
                    </div>
                    <el-input v-model="formData.model2.param3"
                      @input="(value) => (formData.model2.param3 = value.replace(/[^0-9.]/g, '').replace(/^(\d+\.\d{0,4}).*$/, '$1'))"
                      placeholder="保留四位小数" />
                    <el-select v-model="formData.model2.symbol3" placeholder="请选择">
                      <el-option label="lg" value="lg" />
                      <el-option label="ln" value="ln" />
                    </el-select>
                    <div class="el-colC">
                      <span class="italic">ρ</span>
                    </div>
                  </el-col>
                </el-form-item>

                <el-form-item label="受伤与死亡比例" prop="model2.ratio" label-width="270px" :rules="[
                { required: true, message: '受伤与死亡比例必填' },
              
              ]">
                  <el-input maxlength="20" style="width: 220px;" :formatter="(value) => `${value}`.replace(/\D/g,'')"
                    :parser="(value) => value.replace(/\D/g,'')" v-model="formData.model2.ratio"
                    controls-position="right" />
                </el-form-item>
              </el-form>
            </el-col>
          </div>
          <div class="mdbj">
            <el-col :span="24">
              <ModelTitle :number="'三'" :content="'源于《GB/T 30352-2013 地震灾情应急评估》公式A.1、表A.1'" />

            </el-col>
            <el-col :span="24" class="mdbj_content">
              <div style="margin-bottom: 10px;">按区域上传伤亡率与烈度的统计关系文件<el-button type="primary" link
                  @click="handleDownload('0000000000000000000000000000000','伤亡率与烈度模版.zip')">模板下载</el-button></div>
              <el-form-item prop="model3.attachId" :rules="[
                { required: true, message: '文件不能为空' },
              ]">
                <UploadFile v-model="formData.model3.list" @uploadSuccess="uploadSuccess" :limit=1
                  :updateUrl="updateUrl" :downloadFileUrl="downloadFileUrl">
                </UploadFile>
              </el-form-item>
            </el-col>
          </div>
          <div class="mdbj">
            <el-col :span="24">
              <ModelTitle :number="'四'" :content="'源于《GB/T 30352-2013 地震灾情应急评估》公式A.4、A.5'" />
            </el-col>
            <el-col :span="24" class="mdbj_content">
              <el-form :inline="true" class="demo-form-inline" :model="formData" :rules="formRules">
                <el-form-item label="死亡率与毁坏比的关系" label-width="auto" prop="model4.param1" :rules="[
                  { required: true, message: '死亡率与毁坏比的关系' },
                ]">
                  <el-col :span="24" class="flex">
                    <div class="el-colC">
                      <span class="italic">logR =</span>
                    </div>
                    <el-input v-model="formData.model4.param1"
                      @input="(value) => (formData.model4.param1 = value.replace(/[^0-9.]/g, '').replace(/^(\d+\.\d{0,4}).*$/, '$1'))"
                      placeholder="保留四位小数" />
                    <div class="el-colC">
                      <span class="italic">C</span><sup>0.1</sup>
                    </div>
                    <div class="el-colC">
                      <el-icon>
                        <Minus />
                      </el-icon>
                    </div>
                    <el-input v-model="formData.model4.param2"
                      @input="(value) => (formData.model4.param2 = value.replace(/[^0-9.]/g, '').replace(/^(\d+\.\d{0,4}).*$/, '$1'))"
                      placeholder="保留四位小数" />
                  </el-col>
                </el-form-item>

                <el-form-item label="受伤与死亡比例" prop="model4.ratio" label-width="270px" :rules="[
                  { required: true, message: '受伤与死亡比例必填' },
                ]">
                  <el-input style="width: 220px;" :formatter="(value) => `${value}`.replace(/\D/g,'')"
                    :parser="(value) => value.replace(/\D/g,'')" v-model="formData.model4.ratio"
                    controls-position="right" />
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="24" class="mdbj_content">
              <el-descriptions class="margin-top" title="易损性矩阵：上传shp文件压缩包（zip格式）" :column="2" size="large" border>
                <template #extra>
                  <el-button type="primary" link
                    @click="handleDownload('1111111111111111111111111111111','易损性矩阵模版.zip')">模版下载</el-button>
                </template>
                <el-descriptions-item label="结构类型" align="center">选择文件</el-descriptions-item>
                <el-descriptions-item label="结构类型" align="center">选择文件</el-descriptions-item>
                <el-descriptions-item label="多层钢筋混凝土房屋" align="center">
                  <el-form-item prop="model4.list1" style="margin: 0;width: 100%;" :rules="[
                    { required: true, message: '文件不能为空' },
                  ]">
                    <UploadFile v-model="formData.model4.list1" :formName="0" @uploadSuccess="uploadSuccessp"
                      :is-show-tip="false" :updateUrl="updateUrl" :downloadFileUrl="downloadFileUrl" :limit=1>
                    </UploadFile>
                  </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="多层砌体房屋" align="center">
                  <el-form-item prop="model4.list2" style="margin: 0;width: 100%;" :rules="[
                    { required: true, message: '文件不能为空' },
                  ]">
                    <UploadFile v-model="formData.model4.list2" :formName="1" @uploadSuccess="uploadSuccessp"
                      :is-show-tip="false" :updateUrl="updateUrl" :downloadFileUrl="downloadFileUrl" :limit=1>
                    </UploadFile>
                  </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="单层民宅" align="center">
                  <el-form-item prop="model4.list3" style="margin: 0;width: 100%;" :rules="[
                    { required: true, message: '文件不能为空' },
                  ]">
                    <UploadFile v-model="formData.model4.list3" :formName="2" @uploadSuccess="uploadSuccessp"
                      :is-show-tip="false" :updateUrl="updateUrl" :downloadFileUrl="downloadFileUrl" :limit=1>
                    </UploadFile>
                  </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="其他房屋" align="center">
                  <el-form-item prop="model4.list4" style="margin: 0;width: 100%;" :rules="[
                    { required: true, message: '文件不能为空' },
                  ]">
                    <UploadFile v-model="formData.model4.list4" :formName="3" @uploadSuccess="uploadSuccessp"
                      :is-show-tip="false" :updateUrl="updateUrl" :downloadFileUrl="downloadFileUrl" :limit=1>
                    </UploadFile>
                  </el-form-item>
                </el-descriptions-item>
              </el-descriptions>
            </el-col>
          </div>

          <div class="mdbj">
            <el-col style="margin-top: 30px;" :span="24">
              <ModelTitle :number="'五'" :content="'源于《GB/T 30352-2013 地震灾情应急评估》公式A.4、表A.2'" />
            </el-col>
            <el-col :span="24" class="mdbj_content">
              <el-form-item>
                <el-table class="listTables" ref="multipleTableRef" border :data="formData.model5">
                  <el-table-column prop="damageLevel" label="房屋破坏程度" align="right" width="160">
                    <template #default="{row,$index}">
                      <div>
                        {{ {1:'基本完好',2:'轻微破坏',3:'中等破坏' ,4:'严重破坏',5:'毁坏'}[row.damageLevel] }}
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column header-align="center" align="center" label="死亡率R" width="200">
                    <template #default="{ row, $index }">
                      <el-form-item :prop="`model5.${$index}.deadRatio`" :rules="[
                          { required: true, message: '不能为空' },
                        ]">
                        <el-input type="number" v-model="row.deadRatio" placeholder="请输入" :min="0" maxlength="10" />
                      </el-form-item>
                    </template>
                  </el-table-column>
                  <el-table-column header-align="center" align="center" label="受伤率W" width="200">
                    <template #default="{ row, $index }">
                      <el-form-item :prop="`model5.${$index}.injureRatio`" :rules="[
                          { required: true, message: '不能为空' },
                        ]">
                        <el-input type="number" v-model="row.injureRatio" placeholder="请输入" :min="0" maxlength="10" />
                      </el-form-item>
                    </template>
                  </el-table-column>
                </el-table>
              </el-form-item>
            </el-col>
          </div>
        </ContentWrapForm>
      </el-col>
      <el-col :span="24">
        <ContentWrapForm :title="'时间因子'" :pcontent="'白天取值为1，填写夜间系数'">
          <el-form-item>
          </el-form-item>
          <el-col :span="24">
            <el-descriptions title=" " direction="vertical" :column="8" border>
              <el-descriptions-item label="震中烈度" label-align="center" align="center">
                <div class="el-colC">
                  <div>夜间 </div>
                  <div style="min-width: 90px;">
                    (18:00-06:00)
                  </div>
                </div>
              </el-descriptions-item>
              <el-descriptions-item label="VI" label-align="center" align="center">
                <el-form-item style="margin: 0;">
                  <div class="el-colC">
                    <el-input type="number" v-model="formData.model.intensity6" placeholder="请输入" :min="0"
                      maxlength="10" />

                  </div>
                </el-form-item>
              </el-descriptions-item>
              <el-descriptions-item label="VII" label-align="center" align="center">
                <el-form-item style="margin: 0;">
                  <el-input type="number" v-model="formData.model.intensity7" placeholder="请输入" :min="0"
                    maxlength="10" />
                </el-form-item>
              </el-descriptions-item>
              <el-descriptions-item label="VIII" label-align="center" align="center">
                <el-form-item style="margin: 0;">
                  <el-input type="number" v-model="formData.model.intensity8" placeholder="请输入" :min="0"
                    maxlength="10" />
                </el-form-item>
              </el-descriptions-item>
              <el-descriptions-item label="IX" label-align="center" align="center">
                <el-form-item style="margin: 0;">
                  <el-input type="number" v-model="formData.model.intensity9" placeholder="请输入" :min="0"
                    maxlength="10" />
                </el-form-item>
              </el-descriptions-item>
              <el-descriptions-item label="X" label-align="center" align="center">
                <el-form-item style="margin: 0;">
                  <el-input type="number" v-model="formData.model.intensity10" placeholder="请输入" :min="0"
                    maxlength="10" />
                </el-form-item>
              </el-descriptions-item>
              <el-descriptions-item label="XI" label-align="center" align="center">
                <el-form-item style="margin: 0;">
                  <el-input type="number" v-model="formData.model.intensity11" placeholder="请输入" :min="0"
                    maxlength="10" />
                </el-form-item>
              </el-descriptions-item>
              <el-descriptions-item label="XII" label-align="center" align="center">
                <el-form-item style="margin: 0;">
                  <el-input type="number" v-model="formData.model.intensity12" placeholder="请输入" :min="0"
                    maxlength="10" />
                </el-form-item>
              </el-descriptions-item>
            </el-descriptions>
          </el-col>
        </ContentWrapForm>
      </el-col>
      <el-col :span="24">
        <ContentWrapForm :title="'次生灾害'">
          <el-form-item>
          </el-form-item>
          <el-col :span="24">
            <el-descriptions title=" " direction="vertical" :column="8" border>
              <el-descriptions-item label="危险性等级" label-align="center" align="center">
                <div class="el-colC">
                  <div>修正因子</div>
                </div>
              </el-descriptions-item>
              <el-descriptions-item :label="item.name" label-align="center" align="center"
                v-for="(item,index) in reformDataList">
                <div class="el-colC">
                  <el-input type="number" v-model="item.data" placeholder="请输入" :min="0" maxlength="10" />
                </div>
              </el-descriptions-item>
            </el-descriptions>
          </el-col>
        </ContentWrapForm>
      </el-col>
      <el-col :span="24" style="margin-bottom: 72px;">
        <ContentWrapForm :title="'报告使用模型'">
          <el-form-item></el-form-item>
          <el-col :span="24">
          </el-col>
          <el-form-item>
            <el-radio-group v-model="formData.model.defaultModel">
              <el-radio :label="1">模型1</el-radio>
              <el-radio :label="2">模型2</el-radio>
              <el-radio :label="3">模型3</el-radio>
              <el-radio :label="4">模型4</el-radio>
              <el-radio :label="5">模型5</el-radio>
              <el-radio :label="null">空</el-radio>
            </el-radio-group>
          </el-form-item>
        </ContentWrapForm>
      </el-col>

    </el-row>
  </el-form>
  <el-col class="el-colfoot">
    <el-button type="primary" @click="saveForm">保存</el-button>
  </el-col>
</template>

<script setup>
import request from '@/config/axios'
import download from '@/utils/download'
import { getAccessToken } from '@/utils/auth'
import UploadFile from '@/views/responseLevel/populationDensity/create/UploadFileReport.vue'

import ModelTitle from './component/ModelTitle.vue';
import * as casualtyApi from '@/api/casualty/index'
import { parseInt } from 'lodash-es';
const message = useMessage() // 消息弹窗
const updateUrl = ref(import.meta.env.VITE_BASES_URL + '/evaluate/attachment/uploadShpFile')
const downloadFileUrl=ref(import.meta.env.VITE_BASES_URL + '/evaluate/attachment/downLoadFile')
const uploadHeaders = ref({
  Authorization: 'Bearer ' + getAccessToken(),
})
defineOptions({ name: 'Casualties' })
const formLoading = ref(false)
const formRef = ref()
const formData = ref({
  "model1": {
    "symbol": "ln",
    "param1": null,
    "param2": null,
    "param3": null,
    "ratio": null
  },
  "model2": {
    "symbol": "ln",
    "symbol2": "ln",
    "symbol3": "ln",
    "param1": null,
    "param2": null,
    "param3": null,
    "ratio": null
  },
  "model3": {
    "attachId": "",
    list: []
  },
  "model4": {
    "param1": null,
    "param2": null,
    "ratio": null,
    "attachId": "",
    list1: [],
    list2: [],
    list3: [],
    list4: [],
    list: [],
  },
  model5: [
    {
      "damageLevel": "1",
      "deadRatio": null,
      "injureRatio": null
    },
    {
      "damageLevel": "2",
      "deadRatio": null,
      "injureRatio": null
    },
    {
      "damageLevel": "2",
      "deadRatio": null,
      "injureRatio": null
    },
    {
      "damageLevel": "4",
      "deadRatio": null,
      "injureRatio": null
    },
    {
      "damageLevel": "5",
      "deadRatio": null,
      "injureRatio": null
    }
  ],
  "model": {
    "intensity6": null,
    "intensity7": null,
    "intensity8": null,
    "intensity9": null,
    "intensity10": null,
    "intensity11": null,
    "intensity12": null,
    "defaultModel": null
  },
})
const reformData = ref({
  "model1": {
    "symbol": "ln",
    "param1": null,
    "param2": null,
    "param3": null,
    "ratio": null
  },
  "model2": {
    "symbol": "ln",
    "symbol2": "ln",
    "symbol3": "ln",
    "param1": null,
    "param2": null,
    "param3": null,
    "ratio": null
  },
  "model3": {
    "attachId": "",
    list: []
  },
  "model4": {
    "param1": null,
    "param2": null,
    "ratio": null,
    "attachId": "",
    list1: [],
    list2: [],
    list3: [],
    list4: [],
    list: [],
  },
  model5: [
    {
      "damageLevel": "1",
      "deadRatio": null,
      "injureRatio": null
    },
    {
      "damageLevel": "2",
      "deadRatio": null,
      "injureRatio": null
    },
    {
      "damageLevel": "2",
      "deadRatio": null,
      "injureRatio": null
    },
    {
      "damageLevel": "4",
      "deadRatio": null,
      "injureRatio": null
    },
    {
      "damageLevel": "5",
      "deadRatio": null,
      "injureRatio": null
    }
  ],
  "model": {
    "intensity6": null,
    "intensity7": null,
    "intensity8": null,
    "intensity9": null,
    "intensity10": null,
    "intensity11": null,
    "intensity12": null,
    "defaultModel": null
  },
})
const reformDataList = ref([
  {
    name:'较高',
    data:'2'
  },
  {
    name:'高',
    data:'2'
  },
  {
    name: '中',
    data:'1.0'
  },
  {
    name: '低',
    data: '1.0'
  },
  {
    name: '极低',
    data: '1.0'
  }
])
const list = ref([]);
const list4 = ref([]);
const list4data = ref([]);
// 正整数校验
const positiveInteger = (rule, value, callback) => {
  if (value == null) {
    callback()
  } else if (isNaN(value)) {
    return callback(new Error());
  } else if (value.indexOf(".") != -1) {
    callback(new Error());
  } else {
    callback()
  }
}
const formRules = reactive({
  userName: [{ required: true, message: '调整系数不能为空', trigger: 'blur' }, { required: true, message: '请输入正整数', validator: positiveInteger }],
  deptName: [{ required: true, message: '维护人单位不能为空', trigger: 'blur' }, { required: true, message: '请输入正整数', validator: positiveInteger }],
  deptName1: [{ required: true, message: '维护人单位不能为空', trigger: 'blur' }, { required: true, message: '请输入正整数', validator: positiveInteger }],
  basicallyIntact: [{ required: true, message: '损失占比不能为空', trigger: 'blur' }],
  minorDamage: [{ required: true, message: '损失占比不能为空', trigger: 'blur' }],
  moderateDamage: [{ required: true, message: '损失占比不能为空', trigger: 'blur' }],
  seriousDamage: [{ required: true, message: '损失占比不能为空', trigger: 'blur' }],
  collapse: [{ required: true, message: '损失占比不能为空', trigger: 'blur' }],
})

const uploadSuccess = (value) => {
  list.value = value.fileList;
  formData.value.model3.attachId = value.fileList[0].attachId;
  formData.value.model3.list = value.fileList;
  console.log('formData.value', formData.value)
}
const uploadSuccess1 = (value) => {
  console.log('schuan',value);
  
  list4data.value.push(value);
  list4.value.push(value[0].attachId);
  formData.value.model4.attachId = list4.value.join(',');
  console.log('schuan',list4.value);
}

const uploadSuccessp = (value) => {
  list4data.value[value.formName] = value.fileList;
  list4.value[value.formName] = value.fileList[0].attachId;
  formData.value.model4.attachId = list4.value.join(',');
}
const saveForm = async () => {
  // formData.value.model4.list = list4data.value;
    const data = formData.value;
    if(!data.model1.param2 || !data.model1.param3 ){
      message.info('模型1:死亡率公式不全')
      return false
    }
    if(!data.model2.param2 || !data.model2.param3 ){
      message.info('模型2:死亡率公式不全')
      return false
    }
    if(!data.model4.param2  ){
      message.info('模型4:死亡率与毁坏比的关系不全')
      return false
    }
    // if(data.model4.list1.length==0||data.model4.list2.length==0||data.model4.list3.length==0||data.model4.list4.length==0){
    //   message.info('模型4:易损性矩阵结构类型文件不全')
    //   return false
    // }
    data.model1.param1=parseFloat(data.model1.param1)
    data.model1.param2=parseFloat(data.model1.param2)
    data.model1.param3=parseFloat(data.model1.param3)
    data.model1.ratio=parseFloat(data.model1.ratio)
    data.model2.param1=parseFloat(data.model2.param1)
    data.model2.param2=parseFloat(data.model2.param2)
    data.model2.param3=parseFloat(data.model2.param3)
    data.model2.ratio=parseFloat(data.model2.ratio)
    data.model4.param1=parseFloat(data.model4.param1)
    data.model4.param2=parseFloat(data.model4.param2)
    data.model4.ratio=parseFloat(data.model4.ratio)
    data.model5.forEach(item=>{
      item.deadRatio=parseFloat(item.deadRatio);
      item.injureRatio=parseFloat(item.injureRatio);
    })
    data.model.intensity6=parseFloat(data.model.intensity6)
    data.model.intensity7=parseFloat(data.model.intensity7)
    data.model.intensity8=parseFloat(data.model.intensity8)
    data.model.intensity9=parseFloat(data.model.intensity9)
    data.model.intensity10=parseFloat(data.model.intensity10)
    data.model.intensity11=parseFloat(data.model.intensity11)
    data.model.intensity12=parseFloat(data.model.intensity12)
    if(data.model.defaultModel != 'null'){
      data.model.defaultModel=parseFloat(data.model.defaultModel)
    }else{
      data.model.defaultModel = null
    }
  formRef.value.validate(async (valid) => {
    
    if (valid) {
      // 提交请求
      formLoading.value = true
        delete data.model3.list;
        delete data.model4.list;
        delete data.model4.list1;
        delete data.model4.list2;
        delete data.model4.list3;
        delete data.model4.list4;
      try {
        await casualtyApi.ryswUpdate(data)
        message.success('修改成功')
        getDataList()
      } finally {
        formLoading.value = false
      }
    }
  })
}
const getDataList = async () => {
  const data = await casualtyApi.ryswDetails();

  if (data.model3.attachId) {
    console.log('model3');

    data.model3.list[0].name = data.model3.list[0].attachName;
    data.model3.list[0].url = data.model3.list[0].attachId;
  }else{
    data.model3.list=[]
  }
  if (data.model4.attachId) {
    data.model4.list.forEach((item) => {
      item.name = item.attachName;
      item.url = item.attachId;
    })
    data.model4.list1 = [data.model4.list[0]];
    data.model4.list2 = [data.model4.list[1]];
    data.model4.list3 = [data.model4.list[2]];
    data.model4.list4 = [data.model4.list[3]];
    list4.value = data.model4.attachId.split(',');
    list4data.value = data.model4.list;
  }else{
    data.model4.list=[]
    data.model4.list1 = [];
    data.model4.list2 = [];
    data.model4.list3 = [];
    data.model4.list4 = [];
    list4.value = [];
    list4data.value = [];
  }
  formData.value = { ...data };
}
// const downloadFileUrl = ref('/admin-api/attachment/downLoadFile')
// 下载文件
// 下载文件
const handleDownload = async (attachId,title) => {
    if(!attachId)return 
    const res =await request.download({ url: `${downloadFileUrl.value }?attachId=${encodeURIComponent(attachId)}&token=${getAccessToken()}`,headers:uploadHeaders.value });
    download.zip(res, title )
}

onMounted(() => {
  getDataList()
})
</script>
<style lang="scss" scoped>
.italic {
  font-style: italic;
  font-size: 18px;
  font-weight: 400;
  margin-right: 1px;
}
.flex{
  display: flex;
  align-items: center;
}
.el-colC {
  text-align: center;
  margin: 0 2px;
}
.demo-form-inline .el-input {
  --el-input-width: 100px;
}

.demo-form-inline .el-select {
  --el-select-width: 70px;
}
:deep(.is-bordered-label) {
  border: 1px solid #E5E6EB !important;
  background: #EAEFFE !important;
  /* 设置表头背景色 */
  color: #333 !important;
  /* 设置表头文字颜色 */
  font-weight: bold !important;
  height: 32px;
  font-size: 16px;
  line-height: 32px;
}
</style>